package com.hz.Tech2Real.yeyouwang.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hz.Tech2Real.yeyouwang.service.loginService;
import com.hz.Tech2Real.yeyouwang.service.Impl.loginServiceImpl;
import com.hz.Tech2Real.yeyouwang.util.Conts;
import com.hz.Tech2Real.yeyouwang.util.Hmutil;
import com.hz.Tech2Real.yeyouwang.util.MD5;

public class Tech2RealRigsn extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void doDelete(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);

	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		String qmm = request.getParameter("psw");
		String phone = request.getParameter("phone");
		String Verifications1 = request.getParameter("Verification");
		String str = phone;
		int Verifications = Integer.valueOf(Verifications1);
		int codes1 = (Integer) request.getSession().getAttribute(Conts.CODES);
		System.out.println(codes1);
		boolean hm = Hmutil.isChinaPhoneLegal(str);
//		if(hm.isisEmpty())
		if (Verifications == codes1) {
			String password = MD5.getMD5(qmm);

			loginService impl = new loginServiceImpl();

			int list = impl.rigsn(phone, password);

			if (list > 0) {
				response.getWriter()
				.print("<script>alert('恭喜你注册成功，请登录！');location.href='login.jsp';</script>");
			} else {
				response.getWriter()
				.print("<script>alert('注册失败');location.href='login.jsp';</script>");
			}
		} else {
			response.getWriter()
					.print("<script>alert('注册失败！手机短信验证码输入错误！！！');location.href='login.jsp';</script>");
		}

	}
}
